import 'package:flutter/material.dart';

//import 'package:barcode_scan/barcode_scan.dart';


import 'package:flutter/services.dart';

class ScanCodePage extends StatefulWidget {
  ScanCodePage({Key key}) : super(key: key);

  _ScanCodePageState createState() => _ScanCodePageState();
}

class _ScanCodePageState extends State<ScanCodePage> {
  String barcode;

  Future _scan() async {
//    try {
//      String barcode = await BarcodeScanner.scan();
//      setState(() {
//        return this.barcode = barcode;
//      });
//    } on PlatformException catch (e) {
//      if (e.code == BarcodeScanner.CameraAccessDenied) {
//        setState(() {
//          return this.barcode = 'The user did not grant the camera permission!';
//        });
//      } else {
//        setState(() {
//          return this.barcode = 'Unknown error: $e';
//        });
//      }
//    } on FormatException {
//      setState(() => this.barcode =
//          'null (User returned using the "back"-button before scanning anything. Result)');
//    } catch (e) {
//      setState(() => this.barcode = 'Unknown error: $e');
//      print(e);
//    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.photo_camera),
          onPressed: _scan,
        ),
        appBar: AppBar(
          title: Text("扫码"),
        ),
        body: Text("${barcode}")
    );
  }
}
